<html>
<head><meta charset="utf-8"><title>override libc symbol from dependency · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/override.20libc.20symbol.20from.20dependency.html">override libc symbol from dependency</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="221598237"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/override%20libc%20symbol%20from%20dependency/near/221598237" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> devsnek <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/override.20libc.20symbol.20from.20dependency.html#221598237">(Jan 05 2021 at 00:08)</a>:</h4>
<p>so in my <a href="http://lib.rs">lib.rs</a>, i can override libc functions and whatnot by simply declaring no_mangle pub extern c functions with the same names, and that works great. they can also be overridden by declaring a no_mangle pub extern c function in a dependency, and then pub using that function. so my question is this: can the override happen without the person who uses my library explicitly having to type <code>pub use the_lib::__ugly_libc_stuff</code></p>



<a name="221599256"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/override%20libc%20symbol%20from%20dependency/near/221599256" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> devsnek <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/override.20libc.20symbol.20from.20dependency.html#221599256">(Jan 05 2021 at 00:20)</a>:</h4>
<p><span class="user-mention" data-user-id="116015">@Alex Crichton</span> after reading <a href="https://github.com/rust-lang/rust/issues/54135">https://github.com/rust-lang/rust/issues/54135</a> it seems like <code>#[no_mangle]</code> is supposed to imply this behavior? i'm not observing that though.</p>



<a name="221599804"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/override%20libc%20symbol%20from%20dependency/near/221599804" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alex Crichton <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/override.20libc.20symbol.20from.20dependency.html#221599804">(Jan 05 2021 at 00:28)</a>:</h4>
<p><span class="user-mention" data-user-id="219805">@devsnek</span> this isn't really intended behavior per-se and it's not really related to that issue, it's jsut sort of how linkers work</p>



<a name="221599816"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/override%20libc%20symbol%20from%20dependency/near/221599816" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alex Crichton <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/override.20libc.20symbol.20from.20dependency.html#221599816">(Jan 05 2021 at 00:28)</a>:</h4>
<p>if an object file with the symbol is pulled in it will override</p>



<a name="221599831"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/override%20libc%20symbol%20from%20dependency/near/221599831" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alex Crichton <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/override.20libc.20symbol.20from.20dependency.html#221599831">(Jan 05 2021 at 00:28)</a>:</h4>
<p>to understand when/where this happens you'll need to understand how linkers works</p>



<a name="221599834"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/override%20libc%20symbol%20from%20dependency/near/221599834" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alex Crichton <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/override.20libc.20symbol.20from.20dependency.html#221599834">(Jan 05 2021 at 00:28)</a>:</h4>
<p>at a basic level at least</p>



<a name="221600025"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/override%20libc%20symbol%20from%20dependency/near/221600025" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> devsnek <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/override.20libc.20symbol.20from.20dependency.html#221600025">(Jan 05 2021 at 00:31)</a>:</h4>
<p><span class="user-mention" data-user-id="116015">@Alex Crichton</span> i'm not entirely sure what you're saying. i'd like the symbol to always make it to linking, but rust seems to eliminate it.</p>



<a name="221600042"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/override%20libc%20symbol%20from%20dependency/near/221600042" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alex Crichton <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/override.20libc.20symbol.20from.20dependency.html#221600042">(Jan 05 2021 at 00:31)</a>:</h4>
<p>what I'm saying is you need to understand how linking works to understand why it is or isn't included</p>



<a name="221600094"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/override%20libc%20symbol%20from%20dependency/near/221600094" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alex Crichton <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/override.20libc.20symbol.20from.20dependency.html#221600094">(Jan 05 2021 at 00:32)</a>:</h4>
<p>there's lots of caveats and fiddly bits</p>



<a name="221600180"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/override%20libc%20symbol%20from%20dependency/near/221600180" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> devsnek <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/override.20libc.20symbol.20from.20dependency.html#221600180">(Jan 05 2021 at 00:33)</a>:</h4>
<p>well i know how the linker works, the problem is that the function is never given to the linker</p>



<a name="221600300"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/override%20libc%20symbol%20from%20dependency/near/221600300" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alex Crichton <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/override.20libc.20symbol.20from.20dependency.html#221600300">(Jan 05 2021 at 00:34)</a>:</h4>
<p>have you confirmed it's not present in the rlib? or any object file?</p>



<a name="221600355"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/override%20libc%20symbol%20from%20dependency/near/221600355" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> devsnek <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/override.20libc.20symbol.20from.20dependency.html#221600355">(Jan 05 2021 at 00:35)</a>:</h4>
<p>how do you read a wasm-targeted rlib file</p>



<a name="221600375"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/override%20libc%20symbol%20from%20dependency/near/221600375" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alex Crichton <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/override.20libc.20symbol.20from.20dependency.html#221600375">(Jan 05 2021 at 00:35)</a>:</h4>
<p>you'd either inspect IR or use <code>llvm-nm</code></p>



<a name="221600736"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/override%20libc%20symbol%20from%20dependency/near/221600736" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> devsnek <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/override.20libc.20symbol.20from.20dependency.html#221600736">(Jan 05 2021 at 00:41)</a>:</h4>
<p>well it appears to be in the rlib</p>



<a name="221600748"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/override%20libc%20symbol%20from%20dependency/near/221600748" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> devsnek <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/override.20libc.20symbol.20from.20dependency.html#221600748">(Jan 05 2021 at 00:41)</a>:</h4>
<p>(deleted)</p>



<a name="221601084"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/override%20libc%20symbol%20from%20dependency/near/221601084" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> devsnek <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/override.20libc.20symbol.20from.20dependency.html#221601084">(Jan 05 2021 at 00:46)</a>:</h4>
<p>aha it wasn't being linked because the entire library wasn't being linked. as long as <em>something</em> in the library is used, it works</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>